package com.banmao.mall.controller.client;

import com.banmao.mall.model.pojo.Keyword;
import com.banmao.mall.model.pojo.SearchHistory;
import com.banmao.mall.model.vo.BaseRespVO;
import com.banmao.mall.model.vo.client.search.SearchIndexVO;
import com.banmao.mall.service.client.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/wx/search")
public class SearchController {

    @Autowired
    SearchService searchService;

    //获取搜索热词、用户搜索记录、默认搜索词
    @RequestMapping("index")
    public BaseRespVO index() {
        SearchIndexVO searchIndexVO = searchService.index();
        return BaseRespVO.ok(searchIndexVO);
    }

    //根据输入内容获取相关搜索热词
    @RequestMapping("helper")
    public BaseRespVO helper(String keyword){
        /**
         * 此请求的响应体要是String类型的数组
         */
        List<String> keywordList = searchService.helper(keyword);
        return BaseRespVO.ok(keywordList);
    }

    //清楚用户搜索记录
    @RequestMapping("clearhistory")
    public BaseRespVO clearhistory() {
        int error = searchService.clearhistory();
        return BaseRespVO.ok(null);
    }

}
